﻿using System.Linq;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Email Template Repository
    /// </summary>
    public class NotificationRepository : INotificationRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Notification Details by Template Name
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<Notification> FindNotificationByName(string strQuery)
        {
            return _db.Notifications.Where(d => d.Title.Contains(strQuery));
        }

        /// <summary>
        /// Get All Templates
        /// </summary>
        /// <returns></returns>
        public IQueryable<Notification> FindAllNotification()
        {
            return _db.Notifications;
        }

        /// <summary>
        /// Get Notification by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Notification GetNotificationById(int id)
        {
            return _db.Notifications.SingleOrDefault(d => d.NotificationId == id);
        }

        /// <summary>
        /// Add Notification in the Database
        /// </summary>
        /// <param name="notification"></param>
        public void Add(Notification notification)
        {
            _db.Notifications.AddObject(notification);
        }

        /// <summary>
        /// Delete Template from Database
        /// </summary>
        /// <param name="notification"></param>
        public void Delete(Notification notification)
        {
            _db.Notifications.DeleteObject(notification);
        }

        /// <summary>
        /// Save template in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }
    }
}